<?php
/*
 * @Description:
 * @Autor: wangjt
 * @Date: 2020-04-03 17:13:42
 * @LastEditors: wangjt
 * @LastEditTime: 2020-04-16 17:27:16
 */

namespace App\Http\Middleware;

use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
            session()->flash('info', '您已登录，无需再次操作。');
            return redirect('/');
            // return redirect(RouteServiceProvider::HOME);
        }

        return $next($request);
    }
}
